<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属公司">
        <el-radio-group v-model="form.tenant_id" @change="search">
          <el-radio-button :label="0" :value="0"> 全部 </el-radio-button>
          <el-radio-button
            v-for="item in tenantList"
            :key="item.id"
            :label="item.id"
            :value="item.id"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button label="全部">全部</el-radio-button>
          <el-radio-button label="wating">待使用</el-radio-button>
          <el-radio-button label="used">已核销</el-radio-button>
          <el-radio-button label="beginRefunded">退款中</el-radio-button>
          <el-radio-button label="refunded">已退款</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="购买时间">
        <el-date-picker
          v-model="form.create_time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <br />
      <el-form-item label="核销时间">
        <el-date-picker
          v-model="form.valid_time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <br />
      <el-form-item label="商品名称">
        <el-input v-model="form.title" clearable style="width: 168px" />
      </el-form-item>
      <el-form-item label="会员名字">
        <el-input v-model="form.realname" clearable style="width: 168px" />
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="form.tel" clearable style="width: 168px" />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { useFormData } from '@/utils/use-form-data';
  import { getTenantList } from '@/api/tenant';
  import { ref } from 'vue';

  const emit = defineEmits(['search']);

  /** 表单数据 */
  const [form] = useFormData({
    tenant_id: 0,
    status: '全部',
    create_time: '',
    valid_time: '',
    realname: '',
    tel: '',
    title: ''
  });
  /** 租户数据 */
  const tenantList = ref([]);
  /** 获取租户数据 */
  getTenantList({})
    .then((res) => {
      tenantList.value = res.list;
      // console.log(res);
      // console.log(form.site_id);
      // assignFields({
      //   site_id: res[0].site_id
      // });
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };
</script>
